﻿Option Explicit On
Option Strict On

Public Class ExceptionReportForm

#Region " Private Members "

    Private m_DetailsHeight As Integer
    Private m_DetailsVisible As Boolean
    Private m_Exception As Exception

#End Region

#Region " Public Properties "

    Public Property Exception As Exception
        Get
            Return m_Exception
        End Get
        Set(value As Exception)
            m_Exception = value
        End Set
    End Property

#End Region

#Region " Event Handlers "

    Private Sub cmdDetails_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdDetails.Click

        If m_DetailsVisible Then
            m_DetailsVisible = False

            Me.FormBorderStyle = Windows.Forms.FormBorderStyle.FixedDialog
            Me.MinimumSize = New Drawing.Size(0, 0)
            Me.Height = 152
            cmdDetails.Text = "&Details ->"


        Else
            m_DetailsVisible = True
            cmdDetails.Text = "<- &Details"

            If m_DetailsHeight = 0 Then
                m_DetailsHeight = 385
            End If

            Me.MinimumSize = New Drawing.Size(573, 360)

            Me.Height = m_DetailsHeight
            Me.FormBorderStyle = Windows.Forms.FormBorderStyle.Sizable

        End If

    End Sub

    Private Sub ExceptionReportForm_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Me.Height = 152
    End Sub

    Private Sub ExceptionReportForm_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
        If Me.FormBorderStyle = Windows.Forms.FormBorderStyle.Sizable Then
            m_DetailsHeight = Me.Height
        End If
    End Sub

    Private Sub cmdYes_Click(sender As System.Object, e As System.EventArgs) Handles cmdYes.Click
        'Display the Error Form to the user
        Dim ExFormatter As New ExceptionFormatter

        Dim MAPIMail As New MAPI
        MAPIMail.AddRecipientTo(ExceptionManager.ReportingEmailAddress)
        MAPIMail.SendMailPopup(ExceptionManager.SystemName & " - " & ExceptionManager.SystemVersion & " (Unhandled Error)", ExFormatter.GetPlainTextError(m_Exception, ExceptionManager.SystemName, ExceptionManager.SystemVersion))

        DialogResult = Windows.Forms.DialogResult.OK
    End Sub

    Private Sub cmdNo_Click(sender As System.Object, e As System.EventArgs) Handles cmdNo.Click
        DialogResult = Windows.Forms.DialogResult.Cancel
    End Sub

#End Region

End Class